package com.riant.test7;

import org.springframework.aop.ThrowsAdvice;

import java.util.concurrent.*;
import java.util.concurrent.locks.ReentrantLock;

public class Demo01 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Thread thread = new MyThread();
        thread.start();
        Thread thread1 = new Thread(new MyRunnable());
        thread1.start();
        testCallable();
        testExecutorService();
    }

    public static void testCallable() throws ExecutionException, InterruptedException {
        Callable<Integer> callable = new MyCallable();
        FutureTask<Integer> futureTask = new FutureTask<>(callable);
        new Thread(futureTask).start();
        System.out.println(futureTask.get());
    }

    public static void testExecutorService() throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        Callable<Integer> callable = new MyCallable();
        FutureTask<Integer> futureTask = new FutureTask<>(callable);
        Future<Integer> future = (Future<Integer>) executorService.submit(futureTask);
        System.out.println(future.get());
        executorService.shutdown();
    }
}
